<template>
  <div class="app-container">
    <el-tabs v-model="activeTab" type="card" class="query-tabs" @tab-change="tabChange">
      <el-tab-pane label="空间数据" name="0">
        <SpaceData />
      </el-tab-pane>
      <el-tab-pane label="其他数据" name="1">
        <OtherData ref="otherData" />
      </el-tab-pane>
      <el-tab-pane label="统计分析" name="2" v-if="isHasRole !== '1'">
        <StatisticAnalysis ref="analysisRef" />
      </el-tab-pane>
    </el-tabs>
    <router-view></router-view>
  </div>
</template>
<script setup>
import SpaceData from './spaceData.vue'
import OtherData from './otherData.vue'
import StatisticAnalysis from './statisticAnalysis.vue'
import { getRole } from '@/api/achievementSearch/index'
import useTagsViewStore from '@/store/modules/tagsView'

const { proxy } = getCurrentInstance()
const tagsViewStore = useTagsViewStore()
const { visitedViews } = storeToRefs(tagsViewStore)
const activeTab = ref('0')
// 国家级 0  省级 省ID  其他 1
const isHasRole = ref(false)
const tabChange = (val) => {
  console.log(val)
  if (val === '1') {
    proxy.$refs.otherData.getProvinceData()
    proxy.$refs.otherData.getOtherData()
    // proxy.$refs.otherData.resetOtherParams()
  } else if (val === '2') {
    proxy.$refs.analysisRef.activeTab = '0'
    proxy.$refs.analysisRef.getProvinceData()
    // proxy.$refs.analysisRef.resetprojectParams()
    // proxy.$refs.analysisRef.resetAnalysisParams()
  }
}
onMounted(() => {
  getRole().then(res => {
    isHasRole.value = res.data
  })
})

watch(visitedViews, () => {
  let searchNum = visitedViews.value.filter(item => item.path.includes('/achievementSearch')).length

  let newVisitedViews = visitedViews.value.slice(0, -1)
  if (searchNum > 1) {
    newVisitedViews.map((item) => {
      if (item.path.includes('/achievementSearch')) {
        tagsViewStore.delView(item)
      }
    })
  }
}, { deep: true, immediate: true })
</script>
<style lang="scss" scoped>
.app-container {
  width: 100%;
  height: 100%;

  &>.el-tabs {
    height: 100%;

    &>:deep(.el-tabs__content) {
      height: calc(100% - 56px);

      .el-tab-pane {
        height: 100%;
      }
    }
  }
  :deep(.el-space.upload-space) {
    width: 100%;

    .el-space__item {
      width: 100%;
    }
  }
  :deep(.el-space.space-width100) {
    .el-space__item {
      width: 100%;
    }
  }
}
</style>